﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Xml.Linq;

namespace Sexybeauty.Framework.Configration
{
    public class SiteResource
    {
        
        static Resource resource = null;
        static SiteResource()
        {
            XElement xe = XElement.Load(HttpContext.Current.Server.MapPath("/content/config/sitesetting.xml"));
            resource = new Resource()
            {
                Host = new Resource_Host()
                {
                    Domain = xe.Element("host").Element("domain").Value,
                    SiteName = xe.Element("host").Element("name").Value
                },
                Setting = xe.Element("host").Element("setting").Elements()
                        .ToDictionary(
                            xn => { return xn.Name.ToString(); },
                            xn => { return xn.Value; }),
                Company = xe.Element("host").Element("company").Elements()
                    .ToDictionary(
                        xn => { return xn.Name.ToString(); },
                        xn => { return xn.Value; })
            };
        }
        
        #region 字段
        public static string Domain
        {
            get
            {
                return resource.Host.Domain;
            }
        }
        public static string SiteName
        {
            get
            {
                return resource.Host.SiteName;
            }
        }
        public static string CompanyAddress
        {
            get 
            {
                return resource.Company["address"];
            }
        }
        public static string CompanyPhone
        {
            get
            {
                return resource.Company["phone"];
            }
        }
        public static string Logo
        {
            get
            {
                return resource.Setting["logo"];
            }
        }
        #endregion

        #region
        private class Resource
        {
            public Resource_Host Host { get; set; }
            public Dictionary<string, string> Company { get; set; }
            public Dictionary<string, string> Setting { get; set; }
        }
        private class Resource_Host
        {
            /// <summary>
            /// 站点域名 duo500.com
            /// </summary>
            public string Domain { get; set; }
            /// <summary>
            /// 站点名
            /// </summary>
            public string SiteName { get; set; }
        }
        #endregion   
    }
}
